#!/bin/bash

echo "=== 增强版AddressSanitizer调试 ==="
echo ""

# 设置最详细的AddressSanitizer选项
export ASAN_OPTIONS="verbosity=2:halt_on_error=1:symbolize=1:abort_on_error=1:check_initialization_order=1:strict_init_order=1:detect_stack_use_after_return=1:detect_invalid_pointer_pairs=1:print_stats=1"

# 也启用UBSan（未定义行为清理器）如果可用
export UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1"

echo "已启用增强的内存和行为检测："
echo "- 堆栈use-after-return检测"
echo "- 初始化顺序检测"
echo "- 无效指针对检测"
echo "- 内存统计"
echo ""
echo "开始启动程序..."
echo "请进行拖拽操作以触发任何潜在的内存问题"
echo ""

./build_asan/bin/LongImageReader 2>&1 | tee enhanced_debug.log